package web_programing.review.Tcp;

import java.io.*;
import java.net.Socket;
import java.util.Scanner;

/**
 * @author haomin
 * @date 2022/09/27 18:33
 **/
public class Client {
    public static void main(String[] args) throws IOException {
        Socket socket = new Socket("127.0.0.1", 8080);

        InputStream is = socket.getInputStream();
        Scanner scanner = new Scanner(is, "utf-8");

        OutputStream os = socket.getOutputStream();
        OutputStreamWriter writer = new OutputStreamWriter(os, "utf-8");
        PrintWriter printWriter = new PrintWriter(writer);

        // 发送请求
        printWriter.println("我是Java19班的\r\nbanana\r\n");
        printWriter.flush();

        // 读取响应
        String header = scanner.nextLine();
        String chineseWord = scanner.nextLine();
        System.out.println("响应结果：" + chineseWord);

        socket.close();
    }
}